"""LeadIntention schemas for API request/response."""

from __future__ import annotations

from datetime import datetime
from typing import Optional

from pydantic import BaseModel, Field, ConfigDict

from ..models.enums import DemandType, IntentionLevel


class LeadIntentionBase(BaseModel):
    """LeadIntention base schema."""

    demand_type: DemandType = Field(..., description="需求类型")
    budget_min: Optional[int] = Field(None, description="预算下限（元/月 或 总价元）", ge=0)
    budget_max: Optional[int] = Field(None, description="预算上限（元/月 或 总价元）", ge=0)
    area_preferences: Optional[str] = Field(
        None, max_length=500, description='区域偏好（JSON数组字符串，如: ["望京","国贸"]）'
    )
    layout: Optional[str] = Field(None, max_length=50, description="户型需求（如: 2室1厅）")
    requirement_tags: Optional[str] = Field(
        None, max_length=500, description='需求标签（JSON数组字符串，如: ["近地铁","可养宠物"]）'
    )
    priority: int = Field(1, ge=1, le=10, description="优先级（1-10，数字越小优先级越高）")
    intention_level: IntentionLevel = Field(
        IntentionLevel.MEDIUM, description="意向度（high/medium/low/none）"
    )
    notes: Optional[str] = Field(None, description="该意向的详细备注")


class LeadIntentionCreate(LeadIntentionBase):
    """创建 LeadIntention 的请求 schema."""

    lead_id: int = Field(..., description="客户ID", gt=0)


class LeadIntentionUpdate(BaseModel):
    """更新 LeadIntention 的请求 schema（所有字段可选）."""

    demand_type: Optional[DemandType] = None
    budget_min: Optional[int] = Field(None, ge=0)
    budget_max: Optional[int] = Field(None, ge=0)
    area_preferences: Optional[str] = Field(None, max_length=500)
    layout: Optional[str] = Field(None, max_length=50)
    requirement_tags: Optional[str] = Field(None, max_length=500)
    priority: Optional[int] = Field(None, ge=1, le=10)
    intention_level: Optional[IntentionLevel] = None
    notes: Optional[str] = None


class LeadIntentionOut(LeadIntentionBase):
    """LeadIntention 输出 schema."""

    id: int
    lead_id: int
    created_at: datetime
    updated_at: datetime

    model_config = ConfigDict(from_attributes=True)


class LeadIntentionListOut(BaseModel):
    """LeadIntention 列表输出 schema."""

    items: list[LeadIntentionOut]
    total: int
